$(function() {
	setWXConfig(document.location.href);
});
// 定义一个全局变量获取openId
var openId = getOpenId();

// 判定用户是否绑定，未绑定 进入绑定用户页面，绑定进入个人信息页面显示
function checkUserBinded() {
	var href =preUrl+"user/getopenIdByUserNo";
	$.ajax({
		type : "POST",
		url : href,
		async : true,
		dataType : "json",
		data : {"openId" : openId},
		success : function(data) {
			if (data.rspCode=="0002") {
				alert(data.rspMsg);
				window.location.href=preUrl+"wechat/user/binding.html";
			}else if (data.rspCode == "0000") {
				// 判断openId是否取值成功
				var  userId=data.data.id;
				var homeUserNo=data.data.userNo;
				window.location.assign(preUrl+"wechat/user/home.html?userId=" + userId
						+ "&homeUserNo=" + homeUserNo);
			}else {
				alert("服务器繁忙 稍后重试！");
			}
		},
		error:function(data){
			alert("服务器繁忙 稍后重试！");
		}
	});
}
// 消费记录 查询
function queryChargeDetail() {
	var href = preUrl+"user/getopenIdByUserNo";
	$.ajax({
		type : "POST",
		url : href,
		async : true,
		dataType : "json",
		data : {"openId" : openId},
		success : function(data) {
			if (data.data==null) {
				alert("没有绑定用户请绑定！");
				return;
			}else{
				var  userId=data.data[0].id;
				var homeUserNo=data.data[0].homeinfo.hsUserNo;
				// 判断openId是否取值成功
				if (data.rspCode == "0000") {
					window.location.href = preUrl+"wechat/user/payment_record.html?userId=" + userId
					+ "&homeUserNo=" + homeUserNo;
					return true;
				}
			}

		  }

		});
}
// 余额 查询
function toQueryAccountBalance() {
	var href =preUrl+"user/getopenIdByUserNo";
	$.ajax({
		type : "POST",
		url : href,
		async : true,
		dataType : "json",
		data : {"openId" : openId},
		success : function(data) {
			if (data.data==null) {
				alert("没有绑定用户请绑定");
				return;
			}else{
			var  userId=data.data[0].id;
			var homeUserNo=data.data[0].homeinfo.hsUserNo;
			// 判断openId是否取值成功
			if (data.rspCode == "0000") {
				window.location.href = "wechat/user/home.html?userId="+userId+"&homeUserNo=" + homeUserNo;
				return true;
			}
			}
		}
	});
}
// 水量查询
function getwater() {
	var href =preUrl+ "user/getopenIdByUserNo";
	$.ajax({
		type : "POST",
		url : href,
		async : true,
		dataType : "json",
		data : {
			"openId" : openId
		},
		success : function(data) {
			if (data.data==null) {
				alert("没有绑定用户请绑定！");
				return;
			}else{
			var  userId=data.data[0].id;
			var homeUserNo=data.data[0].homeinfo.hsUserNo;
			// 判断openId是否取值成功
			if (data.rspCode == "0000") {
				window.location.href ="wechat/user/query_water.html?userId=" + userId
				+ "&homeUserNo=" + homeUserNo;
			}
		}
		}
	});
}
// 用水申请 t_apply_detail 与房源信息绑定的
function submitApplyInfo() {
	var href =preUrl+ "user/getopenIdByUserNo";
	$.ajax({
		type : "POST",
		url : href,
		async : true,
		dataType : "json",
		data : {"openId" : openId},
		success : function(data) {
			if (data.data==null) {
				alert("没有绑定用户请绑定！");
				return;
			}else{
			var  userId=data.data[0].id;
			var homeUserNo=data.data[0].homeinfo.hsUserNo;
			// 判断openId是否取值成功
			if (data.rspCode == "0000") {
				window.location.href =  "wechat/user/business.html?userId=" + userId
				+ "&homeUserNo=" + homeUserNo;
				return true;
			}
		}
		}
	});
}
// 水务公告 
function queryNoticeList() {
	window.location.href = "wechat/user/notice.html";
}
